/*
 * @Author: your name
 * @Date: 2021-05-30 08:12:16
 * @LastEditTime: 2022-03-27 20:41:46
 * @LastEditors: Please set LastEditors
 * @Description: 二次封装awtk的接口
 * @FilePath: \telescope720P\src\gui_awtk.h
 */
#ifndef GUI_AWTK_H
#define GUI_AWTK_H
#include "awtk.h"
#include "gui_engine.h"
#include <map>
class GuiAwtk : public GuiEngine {
public:
    GuiAwtk();
    ~GuiAwtk();
#if defined(WIN32) && !defined(MINGW)
    virtual bool Init(LPWSTR lpcmdline, void (*appInit)()) override;
#else
    bool Init(unsigned int width, unsigned int height, std::string resPath, void (*appInit)()) override;
#endif
    void UnInit() override;
    /**
     * @brief
     * 按键映射，awtk的键值与业务键值映射表，解决代码耦合问题。
     */
    void KeymapInit();
    Widget* NewWidget() override;
    void RegisterKeyDownEvent(void (*event)(KeyboardValue value)) override;
    Widget* WindowOpen(std::string windowName) override;
    bool WindowClose(Widget* info) override;
    void KeyDownEvent(void* ctx, event_t* e);
    bool IdleQueue(void* ctx) override;
    bool TimerQueue(void* ctx, unsigned int duration) override;
    unsigned int TimerAdd(void* ctx, unsigned int duration) override;
    unsigned int TimerCount() override;
    bool TimerModiy(unsigned int timerId, unsigned int duration) override;
    bool Lookup(Widget* info, const char* name, bool recursive, Widget* value) override;
    bool SlideMenuSetValue(Widget* widget, unsigned int value) override;
    bool UseStyle(Widget* info, const char* style) override;
    bool SetTrText(Widget* info, const char* trText) override;
    bool SetText(Widget* info, const char* text) override;
    bool SetTextUtf8(Widget* info, const char* text) override;
    bool GetTextUtf8(Widget* info, char* text, unsigned int size) override;
    bool CreateAnimator(Widget* info, const char* animation) override;
    bool SetVisible(Widget* info, bool visible) override;
    bool ViewCreate(Widget* info, int x, int y, int w, int h, Widget* value) override;
    bool LabelCreate(Widget* info, int x, int y, int w, int h, Widget* value) override;
    bool SetSelfLayout(Widget* info, const char* params) override;
    bool SetChildrenLayout(Widget* info, const char* params) override;
    bool SetName(Widget* info, const char* name) override;
    bool Destroy(Widget* info) override;
    bool Move(Widget* info, int x, int y) override;
    bool SliderSetValue(Widget* info, double value) override;
    bool CreateImage(Widget* info, int x, int y, unsigned int w, unsigned int h, Widget* value) override;
    bool SetImage(Widget* info, const char* name) override;
    bool ImageSetDrawType(Widget* info, DrawType drawType) override;
    bool LocaleInfoTr(const char* trText, char** outText) override;
    bool LanguageChange(const char* language) override;
    bool EditSetFocus(Widget* info, bool focus) override;
    bool EditSetCursor(Widget* info, unsigned int cursor) override;
    bool EditSetReadOnly(Widget* info, bool readOnly) override;
    bool EditSetTrTips(Widget* info, const char* trTips) override;
    bool SetFloating(Widget* info, bool floating) override;
    unsigned int WidgetOn(Widget* info, WidgitOnEvent evt, Context* ctx) override;
    bool SetLineWrap(Widget* info, bool wrap) override;
    bool SetWordWrap(Widget* info, bool wrap) override;
    bool LabelSetLength(Widget* info, int length) override;
    bool HscrollLabelCreate(Widget* info, int x, int y, int w, int h, Widget* value) override;
    bool HscrollLabelSetDuration(Widget* info, int duration) override;
    bool HscrollLabelSetElipses(Widget* info, bool ellipses) override;
    bool HscrollLabelSetLoop(Widget* info, bool loop) override;
    bool HscrollLabelSetLull(Widget* info, bool lull) override;
    bool HscrollLabelSetOnlyFocus(Widget* info, bool onlyFocus) override;
    bool HscrollLabelSetOnlyParentFocus(Widget* info, bool onlyFocus) override;
    bool HscrollLabelStop(Widget* value) override;
    bool SetFocus(Widget* info, bool focus) override;
    bool DestroyChildren(Widget* info) override;
    bool MleditSetCursor(Widget* info, unsigned int cursor) override;
    bool MleditSetFocus(Widget* info, bool focus) override;
    bool MleditSetOpenImWhenFocused(Widget* info, bool open) override;
    bool DigitClockCreate(Widget* info, int x, int y, int w, int h, Widget* value) override;
    bool DigitClockSetFormat(Widget* info, const std::string& format) override;

private:
    void (*eventCallback)(KeyboardValue value);
    std::map<uint32_t, KeyboardValue> keyMap;
    event_type_t evtMap[static_cast<int>(WidgitOnEvent::EVT_END)];
};
class AwtkWidget : public Widget {
public:
    AwtkWidget();
    ~AwtkWidget();
    bool IsValid() override;
    std::string Name() override;
    void SetWidget(Widget* p) override;
    int GetCoordX() override;
    int GetCoordY() override;

private:
    friend class GuiAwtk;
    /**
     * @brief
     * widget 只传递，不内存管理
     */
    widget_t* widget;
};
#endif